package com.bryant.bryant_weather.ui.home

import android.content.Context
import android.graphics.Color
import android.view.ViewGroup
import com.bryant.bryant_weather.R
import com.bryant.bryant_weather.utils.WeatherUtils
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.qweather.sdk.response.air.v1.AirHourly

class HourAirQualityAdapter : BaseQuickAdapter<AirHourly, QuickViewHolder>() {
    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: AirHourly?) {
        holder.run {
            // 1. 绑定时间点
            setText(R.id.tv_hour, WeatherUtils.isoTo24HourTime(item?.forecastTime.toString()))
            // 2.绑定空气质量分类和指数
            item?.indexes?.let {
                var airIndex = item.indexes[0]
                airIndex?.let {
                    setText(
                        R.id.tv_hour_air_quality,
                        airIndex.aqiDisplay + " | " + airIndex.category
                    )
                    // 设置文字颜色
                    setTextColor(
                        R.id.tv_hour_air_quality, Color.rgb(
                            airIndex.color.red,
                            airIndex.color.green,
                            airIndex.color.blue
                        )
                    )
                }
                setText(
                    R.id.tv_hour_air_quality_level,
                    airIndex.name + "  " + airIndex.level + "级"
                )
            }


        }


    }

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): QuickViewHolder {
        return QuickViewHolder(R.layout.item_hour_air_quality, parent)
    }
}